package com.tuanzhang.mall.goods.domain.valueobj;

import lombok.Getter;

import java.math.BigDecimal;

/**
 * 类功能描述
 *
 * @author wangyl
 * @date 2025/6/17
 */
@Getter
public class Money {

    /**
     * 金额
     */
    private BigDecimal amount;

    /**
     * 币种
     */
    private Integer currency;

    private Money(){

    }

    private Money(BigDecimal amount, Integer currency){
        checkMoneyParams(amount, currency);
        this.amount = amount;
        this.currency = currency;
    }

    private void checkMoneyParams(BigDecimal amount, Integer currency) {
        if (null == amount) {
            throw new IllegalArgumentException("金额不能为空");
        }
        if (amount.compareTo(BigDecimal.ZERO) < 0) {
            throw new IllegalArgumentException("金额不能小于0");
        }
        if (null == currency) {
            throw new IllegalArgumentException("币种不能为空");
        }
    }

    public static Money getMoney(BigDecimal amount, Integer currency) {
        return new Money(amount, currency);
    }
}
